#version 330 core
precision mediump float;

in vec2 tex_coord;
out vec4 frag_color;

uniform sampler2D y_texture;
uniform sampler2D uv_texture;
uniform int format;
uniform vec3 tex_color;

uniform mat3 yuv2rgb;

void main() {
  vec3 yuv;
  yuv.x = texture(y_texture, tex_coord).r;
  if (format == 5) {
    yuv.y = texture(uv_texture, tex_coord).g - 0.5;
    yuv.z = texture(uv_texture, tex_coord).r - 0.5;
  } else if (format == 6) {
    yuv.y = texture(uv_texture, tex_coord).r - 0.5;
    yuv.z = texture(uv_texture, tex_coord).g - 0.5;
  }
  highp vec3 rgb = yuv2rgb * yuv;
  frag_color = vec4(rgb, 1.0) * vec4(tex_color, 1.0f);
}